package dao.impl;

import dao.IItemListDao;
import entities.ItemList;

public class ItemListDao extends CommonDao<ItemList> implements IItemListDao {


	public ItemList find(int id) {
		try {
			return em.find(ItemList.class, id);
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public String getWhereClause(ItemList obj) {
		StringBuilder clause = new StringBuilder();
		clause.append(" ");
		if (obj.getId() != null) {
			if (clause.length() > 1) {
				clause.append(" and");
				clause.append("id = ").append(" obj.getId").append(" ");
			}
		}
		if (obj.getVersion() != null) {
			if (clause.length() > 1) {
				clause.append(" and");
				clause.append("version = ").append(" obj.getVersion")
						.append(" ");
			}
		}
		if (obj.getCategory() != null) {
			if (clause.length() > 1) {
				clause.append(" and");
				clause.append("category = ").append(" obj.getCategory")
						.append(" ");
			}
		}
		if (obj.getName() != null) {
			if (clause.length() > 1) {
				clause.append(" and");
				clause.append("name = ").append(" obj.getName").append(" ");
			}
		}

		return clause.toString();
	}

}